import router from '@/router'
import configStore from '@/stores/configStore'
import publicStore from '@/stores/publicStore'
import { isNull } from "@/utils/common"

router.beforeEach(async (to: any, from: any, next) => {
  // 初始化状态
  publicStore().$reset()
  // 设置头部
  document.title = to.meta.title? to.meta.title : '无'
  // 无需登录
  if(!configStore().isLogin) return next() 
  // 需登录 无需验证token
  if(isNull(to.meta.auth)) return next() 
  if(!isNull(to.meta.auth) && to.meta.auth.find((a:any)=>a == 'user')) return next() 
  // 1.验证token
  if (!configStore().token) return next('/home')
  // 2.验证角色
  // const auth = store.getters.user? store.getters.user.roles : ''
  // if (authList && !auth.some((role : any )=> authList.includes(role))) return next('/noPermission')
  next()
})

router.afterEach(() => {

})
